<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript">
	var filePath = "sss";
</script>
<meta http-equiv="X-UA-Compatible" content="edge" />
<script type="text/javascript" src="${ctx}/jslib/books/video.js"></script>
<c:if test="${fn:contains(sessionInfo.resourceList, '/dictionary/edit')}">
	<script type="text/javascript">
		$.canEdit = true;
	</script>
</c:if>
<c:if test="${fn:contains(sessionInfo.resourceList, '/dictionary/delete')}">
	<script type="text/javascript">
		$.canDelete = true;
	</script>
</c:if>
<title>资源管理</title>
<script type="text/javascript">
	ctx = '${pageContext.request.contextPath}';
</script>

</head>
<script type=text/javascript>
	function doProgressLoop(prog, max, counter) {
		var x = document.getElementById('progress-content').innerHTML;
		var y = parseInt(x);
		if (!isNaN(y)) {
			prog = y;
		}
		counter = counter + 1;
		if (prog < 100) {
			setTimeout("getProgress()", 1000);
			setTimeout("doProgressLoop(" + prog + "," + max + "," + counter	+ ")", 1500);
			document.getElementById('progressBarText').innerHTML = 'upload in progress: '+ prog + '%';
			document.getElementById('progressBarBoxContent').style.width = parseInt(prog)+ '%';
		}
	}

	function getProgress() {
		$.getJSON(ctx + '/ebookHelper/ProgressServlet.do','',function(data){
			document.getElementById('progress-content').innerHTML = data;
		});
		/* $.ajax({
					type : "post",
					dataType : "string",
					url : "${ctx}/ebookHelper/ProgressServlet.do",
					data : "",
					success : function(data) {
					alert(data)
						document.getElementById('progress-content').innerHTML = data;
					},
					error : function(err) {
						document.getElementById('progressBarText').innerHTML = "Error retrieving progress";
					}
				}); */
	}

	function fSubmit() {
		var button = window.document.getElementById("submitButton");
		button.disabled = true;
		var max = 100;
		var prog = 0;
		var counter = 0;
		document.getElementById('progressBar').style.display = 'block';
		document.getElementById('progressBarText').innerHTML = 'upload in progress: 0%';
		getProgress();
		doProgressLoop(prog, max, counter);
		document.getElementById("form1").submit();
	}
</script>
<body>
	<form name="form1" id="form1" action="${ctx}/ebook/AppUpload.action" method="post" enctype="multipart/form-data">
		<span>选择文件</span>
		<div style="padding-bottom:5px;">
			<input type="file" size="48" name="filedata" id='filedata'>
		</div>
		<div id="progressBar" style="display: none;">
			<div id="theMeter">
				<div id="progressBarText"></div>
				<div id="progressBarBox" style="color:Silver;border-width:1px;border-style:Solid;width:300px;TEXT-ALIGN:left">
					<div id="progressBarBoxContent" style="background-color:#3366FF; height:15px; width:0%;TEXT-ALIGN:left"></div>
				</div>
				<div id="progress-content" style="display: none;"></div>
			</div>
		</div>
		<input id='submitButton' tabIndex=3 type=button value="提交" onclick='fSubmit();'>
	</form>
</body>
</html>